
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
# 缓存管理示例
cache_opts = {
    'cache.type': 'file',
    'cache.data_dir': './cache_data',
    'cache.expire': 3600
}
cache = CacheManager(**parse_cache_config_options(cache_opts))

@cache.cache('square_cache', expire=300)
def square(x):
    print("仅首次调用会执行 square...")  # 仅首次调用会执行
    return x * x


square(1)
square(1)